﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using YAPL.Language.Core;
using YAPL.Language.Core.Types;
using YAPL.Language.Core.Lib.GlobalFunctions;
/// <summary>
/// The following project demonstrates use of functions of YAPL core library
/// This is how YAPL program looks in C# programming language
/// </summary>
namespace YAPL.Samples.CoreTest {

	public class Program {
		public static void Main(string[] args) {
			try {
				new concat_strings();
				new main_func();
				GCL.Get(ClassNames.GlobalScope).Methods["main_func"].Call(null);
			}
			catch (Exception e) {
				Console.WriteLine("Runtime exception occured. Message: {0}", e.Message);
			}
			
		}
	}

	public class do_nothing : YAPLFunction {
		public do_nothing() : base("do_nothing", GCL.Get(ClassNames.GlobalScope)) { }

		[Param(0, "string1"), Param(1, "string2")]
		public override YAPLObject Call(Scope scope) {
			ParseScope(scope);
			return null;
		}
	}

	public class concat_strings : YAPLFunction {
		public concat_strings() : base("concat_strings", GCL.Get(ClassNames.GlobalScope)) { }

		[Param(0,"string1"), Param(1,"string2")]
		public override YAPLObject Call(Scope scope) {
			ParseScope(scope);
			var s1 = (YAPLString) scope["string1"];
			var s2 = (YAPLString) scope["string2"];
			return new YAPLString(s1.StrValue + s2.StrValue);
		}
	}

	public class main_func : YAPLFunction {
		public main_func() : base("main_func", GCL.Get(ClassNames.GlobalScope)) {}
		public override YAPLObject Call(Scope scope) {
			ParseScope(scope);
			var ss = new Scope();
			return GCL.Get(ClassNames.GlobalScope).Methods[FunctionNames.Print].Call(ss);
			var s = new Scope();
			s["unnamed0"] = new YAPLString("qwe");
			s["unnamed1"] = new YAPLString("rty");
			GCL.Get(ClassNames.GlobalScope).Methods["concat_strings"].Call(s);
			return null;
		}
	}
}
